# @Author：silence
# @Email：792245022@qq.com
# @Date：2025/3/7 0:32

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

service = Service(ChromeDriverManager().install())

chrome_browser = webdriver.Chrome(service=service)

url = "https://www.baidu.com/"

chrome_browser.get(url)

# 元素定位
# 1、根据 ID 找到对象
button = chrome_browser.find_element(by=By.ID, value="su")

# 2、根据标签属性的属性值来获取对象的
input_box = chrome_browser.find_element(by=By.NAME, value="wd")

# 3、根据 xpath 来获取对象
search_box_by_xpath = chrome_browser.find_element(by=By.XPATH, value='//input[@name="wd"]')

# 4、根据 CSS 选择器来获取对象
search_box_by_css = chrome_browser.find_element(by=By.CSS_SELECTOR, value='input[name="wd"]')

# 5、根据 标签的名字获取对象
search_box_by_tag_name = chrome_browser.find_element(by=By.TAG_NAME, value="input")

# 6、根据 class 获取对象
search_box_by_class_name = chrome_browser.find_element(by=By.CLASS_NAME, value="s_ipt")

# 7、根据 link text 获取对象
search_box_by_link_text = chrome_browser.find_element(by=By.LINK_TEXT, value="百度一下")

print(button)

input()